package com.sztx.pay.data.reportform;

import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.poi.util.StringUtil;

public class ChannelReport {

	public static void main(String[] args) throws IOException, ParseException {
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		
		String pathname = "C:\\Users\\xiaosc\\Desktop\\1.txt";		
		List<String> list = FileUtils.readLines(new File(pathname ));
		
		Map<String, String> timesMap = new HashMap<String, String>();
		Map<String, String> countMap = new HashMap<String, String>();
		
		for (String string : list) {
			String[] temp = string.split("	");
			String key = temp[1]+temp[0];
			
			timesMap.put(key, temp[2]);
			countMap.put(key, temp[3]);
		}
		
		Date startDate = sdf.parse("2016-04-01");
		Date endDate = sdf.parse("2016-05-31");
		
		int diff = DateUtils.truncatedCompareTo(startDate, endDate,  Calendar.DATE);
		while (diff < 1) {			
			String cDate = sdf.format(startDate);
			startDate = DateUtils.addDays(startDate, 1);
			diff = DateUtils.truncatedCompareTo(startDate, endDate,  Calendar.DATE);
			
			String line = "";
			
			line += change(countMap.get(cDate+"000004"), timesMap.get(cDate+"000004"));
			line += "	";
			line += change(countMap.get(cDate+"000005"), timesMap.get(cDate+"000005"));
			line += "	";
			line += change(countMap.get(cDate+"000006"), timesMap.get(cDate+"000006"));
			line += "	";
			line += change(countMap.get(cDate+"000009"), timesMap.get(cDate+"000009"));
			line += "	";
			line += change(countMap.get(cDate+"000002"), timesMap.get(cDate+"000002"));
			line += "	";
			line += change(countMap.get(cDate+"000003"), timesMap.get(cDate+"000003"));
			
			
			System.out.println(line);
		}
		
		

	}
	
	
	private static String change(String count, String times){
		String str = "";
		
		if (count == null || count.isEmpty()) {
			count= "0";
		}
		
		if (times == null || times.isEmpty()) {
			times = "0";
		}
		
		str = count+"	"+times;
		return str;
	}
	


}
